
package com.jzdy.controller;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.support.v4.app.Fragment;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioGroup;

import com.jzdy.R;
import com.jzdy.core.controller.CoreActivity;
import com.jzdy.core.controller.CoreFragmentTabAdapter;
import com.special.ResideMenu.ResideMenu;

@SuppressLint("InflateParams")
public class MainActivity extends CoreActivity implements OnClickListener
{
    private ResideMenu resideMenu;
    public List<Fragment> fragments = new ArrayList<Fragment>();
    private RadioGroup rgs;
    private HomeFragment mHomeFragment;

    @Override
    public int doGetContentViewId()
    {
        // TODO Auto-generated method stub
        return R.layout.main;
    }

    @SuppressLint("NewApi")
    @Override
    public void doInitSubViews(View containerView)
    {
        // TODO Auto-generated method stub
        setUpMenu();
    }

    @Override
    public void doInitDataes()
    {
        // TODO Auto-generated method stub
        mHomeFragment = new HomeFragment();
        fragments.add(mHomeFragment);
        fragments.add(new FavoriteFragment());
        fragments.add(new SetFragment());
        rgs = (RadioGroup) findViewById(R.id.radiogroup);
        CoreFragmentTabAdapter tabAdapter = new CoreFragmentTabAdapter(this, fragments, R.id.fl_body, rgs);
        tabAdapter.setOnRgsExtraCheckedChangedListener(new CoreFragmentTabAdapter.OnRgsExtraCheckedChangedListener()
        {
            @Override
            public void OnRgsExtraCheckedChanged(RadioGroup radioGroup , int checkedId , int index)
            {
                System.out.println("Extra---- " + index + " checked!!! ");
                resideMenu.closeMenu();
                resideMenu.getDisabledSwipeDirection().clear();
                switch (index)
                {
                    case 0:
                        resideMenu.setSwipeDirectionDisable(mHomeFragment.getmViewPager().getCurrentItem() <= 0 ? ResideMenu.DIRECTION_RIGHT : ResideMenu.DIRECTION_LEFT);
                        break;
                    case 1:
                        break;
                    case 2:
                        break;
                    case 3:
                        break;
                }
            }
        });
    }

    @Override
    public void doAfter()
    {
        // TODO Auto-generated method stub
    }

    private void setUpMenu()
    {
        // attach to current activity;
        resideMenu = new ResideMenu(this);
        resideMenu.setBackground(R.drawable.menu_background);
        resideMenu.attachToActivity(this);
        resideMenu.setMenuListener(menuListener);
        //valid scale factor is between 0.0f and 1.0f. leftmenu'width is 150dip. 
        resideMenu.setScaleValue(0.6f);
        // create menu items;
        View view = View.inflate(this, R.layout.main_left_view, null);
        resideMenu.addDiyView(view, ResideMenu.DIRECTION_LEFT);
    }
    private ResideMenu.OnMenuListener menuListener = new ResideMenu.OnMenuListener()
    {
        @Override
        public void openMenu()
        {
        }

        @Override
        public void closeMenu()
        {
        }
    };

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev)
    {
        return resideMenu.dispatchTouchEvent(ev);
    }

    @Override
    public void onClick(View v)
    {
        // TODO Auto-generated method stub
        resideMenu.closeMenu();
    }

    // What good method is to access resideMenu？
    public ResideMenu getResideMenu()
    {
        return resideMenu;
    }
}
